DicomObjects includes the facility to write your own DLLs to implement private transfer syntaxes, and this topic explains how.
Separate routines are normally used for packing and unpacking of data. Routines are searched as below before checking the internal tables, so it would be possible to replace the DicomObjects default (de)compression routines for the various JPEG formats or RLE if required. It is also possible to write routines specifically to convert from one syntax to another, and if a specific transcoding routine is specified, this is used in place of the compression and decompression routines (whether external or intrinsic).
In order for the DLL to be found, the transfer syntax UID(s) to be handled should be created as a key under the DicomObjects appropriate registry path. For transcoding routines, the <Conversion> is simply the names of the source and destination syntaxes, with “TO” in between, e.g. “1.2.840.1234.1TO1.2.840.4321.4”. For (de)compression routines, this must contain the 2 values DllName and Entry, and for transcoding routines, it may contain also contain the Prepare entry:
DllName: The Name of the DLL This must either exist on the system PATH, or be fully qualified
Entry: The name of the entry point for this function
Prepare: An optional function called once before any frames are converted
The appropriate registry paths are:
Compression:
HKEY_LOCAL_MACHINE/Software/Medical Connections/DicomObjects/Compress/<UID>
Decompression:
HKEY_LOCAL_MACHINE/Software/Medical Connections/DicomObjects/Decompress/<UID>
Transcoding:
HKEY_LOCAL_MACHINE/Software/Medical Connections/DicomObjects/Transcode/<Conversion>
The functions to perform the export or export must be callable as standard DLL routines, and in C++, the declarations are:
Pack Function |
Copy Code |
---|---|
extern "C" _declspec(dllexport) int __cdecl PackFunction( byte * source, byte * destination, unsigned int length, unsigned int nx, unsigned int ny, unsigned int planes, unsigned int planarconfig, unsigned int bitsperpixel, const char* TransferSyntax, const char* PhotometricInterpretation, bool issigned, IDispatch* attributes, VARIANT quality) |
Return value is total number of output bytes for the given frame.
Unpack Function |
Copy Code |
---|---|
extern "C" _declspec(dllexport) boolean __cdecl UnPackFunction( byte * source, byte * destination, unsigned int length, unsigned int nx, unsigned int ny, unsigned int planes, unsigned int planarconfig, unsigned int bitsperpixel, const char* TransferSyntax, const char* PhotometricInterpretation, bool issigned, IDispatch* attributes, const char* ImplementationUID) |
Return value is true for success or false for failure
Transcode Function |
Copy Code |
---|---|
extern "C" _declspec(dllexport) unsigned int __stdcall TranscodeFunction( byte * source, byte * dest, unsigned int length, unsigned int nx, unsigned int ny, unsigned int planes, unsigned int planarconfig, unsigned int bpp, const char* InputTransferSyntax, const char* OutputTransferSyntax, const char* ColourSpace, bool issigned, IDispatch* attributes, VARIANT quality) |
Return value is the number of bytes written for this frame.
The pack, unpack and transcode functions work on one frame at a time on request, and are called after the non-pixel data has been written, but for transcoding it may also be necessary to modify other data elements, so the prepare function allows this to happen, being called once before any data is written.
Prepare Function |
Copy Code |
---|---|
extern "C" _declspec(dllexport) unsigned int __stdcall PrepareFunction( const char* InputTransferSyntax, const char* OutputTransferSyntax, const char* ColourSpace, IDispatch* attributes, VARIANT quality, char OutputColourSpace[20], char LossyDescription[128], float & offset, float & scale, bool isCompressed, byte * FirstFrame) |
If errors occur in any of these functions, they may throw standard C++ exceptions.
In all cases, the destination buffer is allocated (and freed when necessary) by DicomObjects. For decompression, the buffer will be of exactly the required size, as calculated from the image dimensions and bit depth. For compression, the buffer is 1.5x the uncompressed size – enough to cope with even the worst compression scheme on random data!
Use of these facilities is an advanced technique and advice is available from Medical Connections if required.